package com.justgame.project.service.just.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.JustGamePlatformDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.service.JustGamePlatformService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/just/game-platform")
@AllArgsConstructor
public class JustGamePlatformController {

    private final JustGamePlatformService gamePlatformService;

    @GetMapping("/list")
    public Result<?> getList(PageRequest pageRequest, JustGamePlatformDTO dto) {
        return Result.OK(gamePlatformService.getList(pageRequest, dto));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> addGameType(@Valid @RequestBody JustGamePlatformDTO dto) {
        return Result.OK(gamePlatformService.save(dto));
    }

    @DeleteMapping("/delete")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> deleteGameType(@RequestBody JustGamePlatformDTO dto) {
        return Result.OK(gamePlatformService.Delete(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> updateById(@RequestBody JustGamePlatformDTO dto) {
        return Result.OK(gamePlatformService.updateById(dto));
    }

}
